﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections;
using CCF20Model;
using WiseLinkWPF.Windows.Controls.GridView;
using WiseLinkWPF.Windows.Controls;
using System.Printing;
using GridViewColumn = WiseLinkWPF.Windows.Controls.GridViewColumn;

namespace CCF20Module
{
    /// <summary>
    /// Interaction logic for RoleDetail.xaml
    /// </summary>
    public partial class ChoseColumn : Window
    {
        private IEnumerable MySource;
        private RadGridView MyGrid;
        private string MyType;
        public ChoseColumn(IEnumerable source, RadGridView grid,string type)
        {
            InitializeComponent();
            MySource = source;
            MyGrid = grid;
            MyType = type;

          
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (GridViewColumn column in MyGrid.Columns.OfType<GridViewColumn>())
            {
                if (!column.IsVisible)
                {
                    this.AvailableColumn.Items.Add(column.UniqueName);
                }
            }
            foreach (GridViewColumn column in MyGrid.Columns.OfType<GridViewColumn>())
            {
                if (column.IsVisible)
                {
                    this.currentColumn.Items.Add(column.UniqueName);
                }
            }
        }
        

        private void ChangeColumn_Click(object sender, RoutedEventArgs e)
        {
            string action = ((Button)sender).Tag.ToString();
            switch (action)
            {
                case "AddColumn":
                    AddColumn();
                    break;
                case "RemoveColumn":
                    RemoveColumn();
                    break;
                default:
                    break;

            }
            
        }
        private void AddColumn()
        {
            if (null != AvailableColumn.SelectedItem)
            {
                string strSelected = AvailableColumn.SelectedItem.ToString();
                this.AvailableColumn.Items.Remove(strSelected);
                this.currentColumn.Items.Add(strSelected);
                MyGrid.Columns[strSelected].IsVisible = true;
            }
        }
        private void RemoveColumn()
        {
            if (null != currentColumn.SelectedItem)
            {
                string strSelected = currentColumn.SelectedItem.ToString();
                this.currentColumn.Items.Remove(strSelected);
                this.AvailableColumn.Items.Add(strSelected);
                MyGrid.Columns[strSelected].IsVisible = false;
            }
        }
        private void currentColumn_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            RemoveColumn();
        }

        private void AvailableColumn_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            AddColumn();
        }

    }
}
